import React from "react";
import axios from "axios";

function App() {
  const Request = axios.create({
    baseURL: "http://localhost:9000",
    timeout: 5000,
  });
  const upload = async (e) => {
    const file = e.target.files[0];
    if (!file) {
      alert("没有选中文件");
      return;
    }

    const formData = new FormData();
    formData.append("file", file);
    formData.append("filename", file.name);

    let { data } = await Request.post("/files", formData);

    console.log(data);
    if (data.code === 200) {
      alert(data.message);
    }
  };

  return (
    <div>
      <input type="file" onChange={upload} />
    </div>
  );
}

export default App;
